package com.ndp.fb.walle.business.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ndp.fb.exception.BusinessException;
import com.ndp.fb.rdb.api.ProductConfigurationRdbService;
import com.ndp.fb.rdb.model.ProductConfiguration;
import com.ndp.fb.walle.business.ProductConfigurationService;
import com.ndp.fb.walle.model.bo.productconfiguration.result.ProductConfigurationBo;
import com.ndp.fb.walle.util.ConversionUtils;

/**
 * Created by infi on 2015/1/29.
 */
@Component
public class ProductConfigurationServiceImpl implements ProductConfigurationService {
    private final org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());

    @Reference
    private ProductConfigurationRdbService poductConfigurationRdbServices;

    @Override
    public List<ProductConfigurationBo> findAllProductConfigurationByConnectionObjectId(Long connectionObjectId, String userId) throws BusinessException {
        List<ProductConfigurationBo> configurationBoList = new ArrayList<>();
        List<ProductConfiguration> configurationList = poductConfigurationRdbServices.findByFbConnectionObjectIdInUse(connectionObjectId, userId);
        for (ProductConfiguration productConfiguration : configurationList) {
            ProductConfigurationBo productConfigurationBo = new ProductConfigurationBo();
            ConversionUtils.conversion(productConfiguration, productConfigurationBo);
            configurationBoList.add(productConfigurationBo);
        }
        return configurationBoList;
    }

    @Override
    public ProductConfigurationBo findProductConfigurationById(Long productConfigurationId) throws BusinessException {
        ProductConfigurationBo productConfigurationBo = new ProductConfigurationBo();
        ProductConfiguration productConfiguration = poductConfigurationRdbServices.findById(productConfigurationId);
        ConversionUtils.conversion(productConfiguration, productConfigurationBo);
        return productConfigurationBo;
    }

	@Override
	public ProductConfigurationBo findByFbConnectionObjectIdAndPlatForm(Long connectionObjectId, String platform) {
		ProductConfiguration productConfiguration = poductConfigurationRdbServices.findByFbConnectionObjectIdAndPlatForm(connectionObjectId, platform);
		ProductConfigurationBo productConfigurationBo = new ProductConfigurationBo();
        ConversionUtils.conversion(productConfiguration, productConfigurationBo);
		return  productConfigurationBo;
	}

}
